// by Xeno
#define __ctrl(numcontrol) (_XD_display displayCtrl numcontrol)
private ["_ok", "_XD_display", "_ctrl", "_rarray", "_vdindex", "_i", "_index", "_glindex", "_str", "_ar", "_counter", "_oldsliderpos"];

disableSerialization;

_ok = createDialog "XD_SettingsDialog";

_XD_display = uiNameSpace getVariable "X_SETTINGS_DIALOG";

if (d_disable_viewdistance) then {
	_ctrl ctrlEnable false;
	__ctrl(1999) ctrlSetText "Viewdistance";
	__ctrl(1997) ctrlSetText "";
} else {
	sliderSetRange [1000, 200, d_MaxViewDistance];
	sliderSetPosition [1000, viewDistance];
	__ctrl(1999) ctrlSetText ("Viewdistance: " + str(round viewDistance));
	_oldsliderpos = sliderPosition 1000;
};

_ctrl = _XD_display displayCtrl 1001;

_glindex = -1;
{
	_index = _ctrl lbAdd _x;
	if (d_grasslayer_index == _index) then {_glindex = _index};
} forEach ["No Gras", "Medium Gras", "Full Gras"];

_ctrl lbSetCurSel _glindex;
if (d_Terraindetail == 1) then {
	_ctrl ctrlEnable false;
	__ctrl(1998) ctrlSetText "Gras Layer";
	__ctrl(1996) ctrlSetText "";
};

_ctrl = _XD_display displayCtrl 1002;
if (!d_dont_show_player_markers_at_all) then {
	{_ctrl lbAdd _x} forEach ["Off", "With Names", "Markers Only", "Role only", "Health"];
	_ctrl lbSetCurSel d_show_player_marker;
} else {
	_ctrl ctrlShow false;
	__ctrl(1500) ctrlShow false;
	__ctrl(1501) ctrlShow false;
};

_ctrl = _XD_display displayCtrl 1602;
{_ctrl lbAdd _x} forEach ["Off", "With Names", "Role only", "Health"];
_ctrl lbSetCurSel d_show_player_namesx;

__ctrl(2001) ctrlSetText str(d_points_needed select 0);
__ctrl(2002) ctrlSetText str(d_points_needed select 1);
__ctrl(2003) ctrlSetText str(d_points_needed select 2);
__ctrl(2004) ctrlSetText str(d_points_needed select 3);
__ctrl(2005) ctrlSetText str(d_points_needed select 4);
__ctrl(2006) ctrlSetText str(d_points_needed select 5);

_str = "Own side: " + d_own_side + "\n";
_str = _str + "Enemy side: " + d_enemy_side;
_str = _str + "\n";
_str = _str + "Island: " + (getText (configFile >> "CfgWorlds" >> worldName >> "description")) + "\n";
_str = _str + "Initial viewdistance: " + str(d_InitialViewDistance) + "\n";
_str = _str + "Maximum viewdistance: " + str(d_MaxViewDistance) + "\n";
_str = _str + "Usable main weaponry: All\n";
_str = _str + "With R3F Revive\n";
_str = _str + "With R3F Arty and Log\n";
_str = _str + "Public Mission Screen: " + (if (PublicMissionScreen) then {"Yes\n"} else {"No\n"});
_str = _str + "Show player marker direction: " + (if (d_p_marker_dirs) then {"Yes\n"} else {"No\n"});
_str = _str + "Show vehicle marker direction: " + (if (d_v_marker_dirs) then {"Yes\n"} else {"No\n"});
_str = _str + "Player marker type: " + d_p_marker + "\n";
_str = _str + "Teamstatus Dialog enabled: " + (if (d_use_teamstatusdialog) then {"Yes\n"} else {"No\n"});
_str = _str + "With MHQ Respawn/Teleport: " + (if (d_WithMHQTeleport) then {"Yes\n"} else {"No\n"});
_str = _str + "Enemy skill: " + (switch (EnemySkill) do {case 1: {"Low"};case 2: {"Normal"};case 3: {"High"};}) + "\n";
_str = _str + "Armor at main targets: " + (switch (WithLessArmor) do {case 0: {"Normal"};case 1: {"Less"};case 2: {"None"};}) + "\n";
_str = _str + "With teleport to base: " + (if (WithTeleToBase) then {"Yes\n"} else {"No\n"});
_str = _str + "Block spacebar scanning: " + (if (d_BlockSpacebarScanning) then {"Yes\n"} else {"No\n"});
_str = _str + "Gras visible at missionstart: " + (if (d_GrassAtStart) then {"Yes\n"} else {"No\n"});
_str = _str + "MHQ vehicles (create): ";
for "_i" from 0 to (count d_create_bike - 1) do {
	_str = _str + ([d_create_bike select _i,0] call XfGetDisplayName);
	if (_i < (count d_create_bike - 1)) then {
		_str = _str + ", ";
	};
};
_str = _str + "\n";
_str = _str + "Time a player has to wait until he can create a new vehicle at a MHQ: " + str(VecCreateWaitTime) + "\n";

_str = _str + "Maximum number of ammoboxes: " + str(d_MaxNumAmmoboxes) + "\n";
_str = _str + "Ammoboxes currently in use: " + str(["ammo_boxes",0] call XNetGetJIP) + "\n";
_str = _str + "Time to wait until an ammobox can be dropped/loaded again: " + str(d_drop_ammobox_time) + "\n";

_str = _str + "Vehicles able to load ammoboxes: ";
if (count d_check_ammo_load_vecs > 0) then {
	for "_i" from 0 to (count d_check_ammo_load_vecs - 1) do {
		_str = _str + ([d_check_ammo_load_vecs select _i,0] call XfGetDisplayName);
		if (_i < (count d_check_ammo_load_vecs - 1)) then {_str = _str + ", "};
	};
} else {
	_str = _str + "All";
};
_str = _str + "\n";

_str = _str + "MG gunners able to build mg nest: " + (if (d_with_mgnest) then {"Yes\n"} else {"No\n"});
if (WithJumpFlags == 1) then {
	_str = _str + "AAHALO jump available at flag at base: " + (if (ParaAtBase == 0) then {"Yes\n"} else {"No\n"});
	if (ParaAtBase == 0) then {_str = _str + "Time between two AAHALO jumps from base flag: " + str(d_HALOWaitTime/60) + "\n"};
	_str = _str + "AAHALO jump start height: " + str(HALOJumpHeight) + "\n";
	if (d_jumpflag_vec != "") then {_str = _str + "Create the following vehicle at jump flag instead parajump: " + d_jumpflag_vec + "\n"};
};

_str = _str + "Enemy armored vehicles locked: " + (if (d_LockArmored == 0) then {"Yes\n"} else {"No\n"});

_str = _str + "Enemy cars locked: " + (if (d_LockCars == 0) then {"Yes\n"} else {"No\n"});

_str = _str + "Enemy air vehicles locked: " + (if (d_LockAir == 0) then {"Yes\n"} else {"No\n"});

if (WithChopHud) then {
	_str = _str + "Chopper hud on: " +(if (d_chophud_on) then {"Yes\n"} else {"No\n"});
};

_str = _str + "Show chopper welcome message: " + (if (d_show_chopper_welcome) then {"Yes\n"} else {"No\n"});

_str = _str + "Spawning Air AI: " + (if (WithAirKiSpawn) then {"Yes\n"} else {"No\n"});
_str = _str + "Air AI Respawn Interval: " + str(d_airki_respawntime) + "s\n";
_str = _str + "With Air Radar: " + (if (WithAntiAirRadar) then {"Yes\n"} else {"No\n"});



_str = _str + "";
// don't forget to add \n, but not when adding the last string part
__ctrl(2107) ctrlSetText _str;

_str = "";
{
	_med = missionNamespace getVariable _x;
	if (!isNull _med && isPlayer _med) then {
		if (_str != "") then {_str = _str + ", "};
		_str = _str + (if (alive _med) then {name _med} else {"(Dead)"});
	};
} forEach d_is_medic;

if (_str == "") then {_str = "No human players are medics"};
__ctrl(2008) ctrlSetText _str;

_str = "";
{
	_art = missionNamespace getVariable _x;
	if (!isNull _art && isPlayer _art) then {
		if (_str != "") then {_str = _str + ", "};
		_str = _str + (if (alive _art) then {name _art} else {"(Dead)"});
	};
} forEach d_can_use_artillery;

if (_str == "") then {_str = "No human players are artillery operators"};
__ctrl(2009) ctrlSetText _str;

_str = "";
{
	_eng = missionNamespace getVariable _x;
	if (!isNull _eng && isPlayer _eng) then {
		if (_str != "") then {_str = _str + ", "};
		_str = _str + (if (alive _eng) then {name _eng} else {"(Dead)"});
	};
} forEach d_is_engineer;

if (_str == "") then {_str = "No human players are engineers"};
__ctrl(2010) ctrlSetText _str;

if (d_disable_viewdistance) then {
	waitUntil {!dialog || !alive player};
} else {
	while {alive player && dialog} do {
		if (_oldsliderpos != (sliderPosition 1000)) then {
			_slpos = sliderPosition 1000;
			_nvd = floor _slpos;
			setViewDistance _nvd;
			__ctrl(1999) ctrlSetText ("Viewdistance: " + str(_nvd));
			_oldsliderpos = _slpos;
		};
		sleep 0.05;
	};
};

if (!alive player) then {closeDialog 0};